from flask import *
from io import BytesIO
import requests
import os

app = Flask(__name__)
app.secret_key = 'C-i7tyW8~gmckBS'


@app.route("/", methods=['GET'])
def home():
    ls = os.listdir('./templates/')
    la = []
    for i in ls:
        name = i[0:-5]
        la.append(name)
    la.remove('base')
    return str(la)


@app.route("/<name>", methods=['GET'])
def reto(name=''):
    try:return render_template(name+'.html')
    except:return 'No'


@app.route('/api/down', methods=['GET'])
@app.route('/api/down/', methods=['GET'])
def markdown_download():
    tar = request.values.get('tar', '')
    mod = request.values.get('mod', 'str')
    try:req = requests.get(tar)
    except:return ''
    if mod == 'str':
        return req.text
    if mod == 'byt':
        return req.content


if __name__ == '__main__':
    app.run(host="0.0.0.0", port=80, debug=True)